// IconToolBar.cpp : implementation file
//

#pragma once
#include "stdafx.h"
#include "IconToolBar.h"
#include "Celsus.h"

// CIconToolBar

IMPLEMENT_DYNAMIC(CIconToolBar, CToolBar)
CIconToolBar::CIconToolBar()
{
	m_nDropDowns = 0;
}

CIconToolBar::~CIconToolBar()
{
}


BEGIN_MESSAGE_MAP(CIconToolBar, CToolBar)
	ON_WM_ERASEBKGND()
END_MESSAGE_MAP()



// CIconToolBar message handlers

void CIconToolBar::BuildToolbar(void)
{
	INT nButton = -1;
	TBBUTTON tbb;
	INT nIndex = 0;
	BOOL bShowSep = FALSE;
	BOOL bShowButtonText = FALSE;

	// clear button structure
	memset(&tbb, 0, sizeof( TBBUTTON ));
	// check for text
	bShowButtonText = TRUE;

	// set common attributes for toolbar
	tbb.dwData = 0;

	// add check online button
	tbb.iBitmap = LoadIconFile( IDI_ICON_WEBCHECK, NULL, IDI_ICON_WEBCHECK_D );
	tbb.idCommand = ID_REQUEST_CHECKONLINE;
	tbb.fsStyle = BTNS_BUTTON | TBBS_NOPREFIX;
	tbb.fsState = TBSTATE_ENABLED;
	if( bShowButtonText )
		nIndex = GetToolBarCtrl().AddStrings( _T("Online") );
	else
		nIndex = -1;
	tbb.iString = nIndex;
	//tbb.fsStyle |= BTNS_AUTOSIZE;
	GetToolBarCtrl().AddButtons(1, &tbb);

	// add separator
	tbb.iBitmap = I_IMAGENONE;
	tbb.idCommand = -1;
	tbb.fsStyle = TBSTYLE_SEP;
	tbb.fsState = TBSTATE_ENABLED;
	tbb.iString = -1;
	GetToolBarCtrl().AddButtons(1, &tbb);

	// add check find button
	tbb.iBitmap = LoadIconFile( IDI_ICON_FIND );
	tbb.idCommand = ID_EDIT_FIND_REQUEST;
	tbb.fsStyle = BTNS_BUTTON | TBBS_NOPREFIX;
	tbb.fsState = TBSTATE_ENABLED;
	if( bShowButtonText )
		nIndex = GetToolBarCtrl().AddStrings( _T("Find") );
	else
		nIndex = -1;
	tbb.iString = nIndex;
	//tbb.fsStyle |= BTNS_AUTOSIZE;
	GetToolBarCtrl().AddButtons(1, &tbb);

	// add check edit button
	tbb.iBitmap = LoadIconFile( IDI_ICON_EDIT, NULL, IDI_ICON_EDIT_D );
	tbb.idCommand = ID_REQUEST_EDIT;
	tbb.fsStyle = BTNS_BUTTON | TBBS_NOPREFIX;
	tbb.fsState = TBSTATE_ENABLED;
	if( bShowButtonText )
		nIndex = GetToolBarCtrl().AddStrings( _T("Edit") );
	else
		nIndex = -1;
	tbb.iString = nIndex;
	//tbb.fsStyle |= BTNS_AUTOSIZE;
	GetToolBarCtrl().AddButtons(1, &tbb);

	// add notes button
	tbb.iBitmap = LoadIconFile( IDI_ICON_NOTES, NULL, IDI_ICON_NOTES_D );
	tbb.idCommand = ID_REQUEST_NOTES;
	tbb.fsStyle = BTNS_BUTTON | TBBS_NOPREFIX;
	tbb.fsState = TBSTATE_ENABLED;
	if( bShowButtonText )
		nIndex = GetToolBarCtrl().AddStrings( _T("Notes") );
	else
		nIndex = -1;
	tbb.iString = nIndex;
	//tbb.fsStyle |= BTNS_AUTOSIZE;
	GetToolBarCtrl().AddButtons(1, &tbb);

	// add separator
	tbb.iBitmap = I_IMAGENONE;
	tbb.idCommand = -1;
	tbb.fsStyle = TBSTYLE_SEP;
	tbb.fsState = TBSTATE_ENABLED;
	tbb.iString = -1;
	GetToolBarCtrl().AddButtons(1, &tbb);

	//// add refresh button
	//tbb.iBitmap = LoadIconFile( IDI_ICON_REFRESH );
	//tbb.idCommand = ID_REQUEST_REFRESH;
	//tbb.fsStyle = BTNS_BUTTON | TBBS_NOPREFIX;
	//tbb.fsState = TBSTATE_ENABLED;
	//if( bShowButtonText )
	//	nIndex = GetToolBarCtrl().AddStrings( _T("Refresh") );
	//else
	//	nIndex = -1;
	//tbb.iString = nIndex;
	////tbb.fsStyle |= BTNS_AUTOSIZE;
	//GetToolBarCtrl().AddButtons(1, &tbb);

	//// add separator
	//tbb.iBitmap = I_IMAGENONE;
	//tbb.idCommand = -1;
	//tbb.fsStyle = TBSTYLE_SEP;
	//tbb.fsState = TBSTATE_ENABLED;
	//tbb.iString = -1;
	//GetToolBarCtrl().AddButtons(1, &tbb);

	if( !appConfig.m_Options.bDisableMyView )
	{
		// add claim
		tbb.iBitmap = LoadIconFile( IDI_ICON_CLAIM, NULL, IDI_ICON_CLAIM_D );
		tbb.idCommand = ID_REQUEST_CLAIM;
		tbb.fsStyle = BTNS_BUTTON | TBBS_NOPREFIX;
		tbb.fsState = TBSTATE_ENABLED;
		if( bShowButtonText )
			nIndex = GetToolBarCtrl().AddStrings( _T("Claim") );
		else
			nIndex = -1;
		tbb.iString = nIndex;
		//tbb.fsStyle |= BTNS_AUTOSIZE;
		GetToolBarCtrl().AddButtons(1, &tbb);
	}

	// add send to library
	tbb.iBitmap = LoadIconFile( IDI_ICON_SEND_LIBRARY, NULL, IDI_ICON_SEND_LIBRARY_D );
	tbb.idCommand = ID_REQUEST_SENDTOLIBRARY;
	tbb.fsStyle = BTNS_BUTTON | TBBS_NOPREFIX;
	tbb.fsState = TBSTATE_ENABLED;
	if( bShowButtonText )
		nIndex = GetToolBarCtrl().AddStrings( _T("Library") );
	else
		nIndex = -1;
	tbb.iString = nIndex;
	//tbb.fsStyle |= BTNS_AUTOSIZE;
	GetToolBarCtrl().AddButtons(1, &tbb);

	// add hold
	tbb.iBitmap = LoadIconFile( IDI_ICON_HOLD, NULL, IDI_ICON_HOLD_D );
	tbb.idCommand = ID_REQUEST_MARKASHELD;
	tbb.fsStyle = BTNS_BUTTON | TBBS_NOPREFIX;
	tbb.fsState = TBSTATE_ENABLED;
	if( bShowButtonText )
		nIndex = GetToolBarCtrl().AddStrings( _T("Hold") );
	else
		nIndex = -1;
	tbb.iString = nIndex;
	//tbb.fsStyle |= BTNS_AUTOSIZE;
	GetToolBarCtrl().AddButtons(1, &tbb);

	// add split
	tbb.iBitmap = LoadIconFile( IDI_ICON_SPLIT, NULL, IDI_ICON_SPLIT_D );
	tbb.idCommand = ID_REQUEST_SPLIT;
	tbb.fsStyle = BTNS_BUTTON | TBBS_NOPREFIX;
	tbb.fsState = TBSTATE_ENABLED;
	if( bShowButtonText )
		nIndex = GetToolBarCtrl().AddStrings( _T("Split") );
	else
		nIndex = -1;
	tbb.iString = nIndex;
	//tbb.fsStyle |= BTNS_AUTOSIZE;
	GetToolBarCtrl().AddButtons(1, &tbb);

	// add combine
	tbb.iBitmap = LoadIconFile( IDI_ICON_COMBINE, NULL, IDI_ICON_COMBINE_D );
	tbb.idCommand = ID_REQUEST_COMBINE;
	tbb.fsStyle = BTNS_BUTTON | TBBS_NOPREFIX;
	tbb.fsState = TBSTATE_ENABLED;
	if( bShowButtonText )
		nIndex = GetToolBarCtrl().AddStrings( _T("Combine") );
	else
		nIndex = -1;
	tbb.iString = nIndex;
	//tbb.fsStyle |= BTNS_AUTOSIZE;
	GetToolBarCtrl().AddButtons(1, &tbb);

	// add separator
	tbb.iBitmap = I_IMAGENONE;
	tbb.idCommand = -1;
	tbb.fsStyle = TBSTYLE_SEP;
	tbb.fsState = TBSTATE_ENABLED;
	tbb.iString = -1;
	GetToolBarCtrl().AddButtons(1, &tbb);

	// add print button
	tbb.iBitmap = LoadIconFile( IDI_ICON_PRINT, NULL, IDI_ICON_PRINT_D );
	tbb.idCommand = ID_REQUEST_PRINTSELECTED;
	tbb.fsStyle = BTNS_BUTTON | TBBS_NOPREFIX;
	tbb.fsState = TBSTATE_ENABLED;
	if( bShowButtonText )
		nIndex = GetToolBarCtrl().AddStrings( _T("Print") );
	else
		nIndex = -1;
	tbb.iString = nIndex;
	//tbb.fsStyle |= BTNS_AUTOSIZE;
	GetToolBarCtrl().AddButtons(1, &tbb);

	// add send to process button
	tbb.iBitmap = LoadIconFile( IDI_ICON_SEND_PROCESS, NULL, IDI_ICON_SEND_PROCESS_D );
	tbb.idCommand = ID_REQUEST_SENDTOPROCESSING;
	tbb.fsStyle = BTNS_BUTTON | TBBS_NOPREFIX;
	tbb.fsState = TBSTATE_ENABLED;
	if( bShowButtonText )
		nIndex = GetToolBarCtrl().AddStrings( _T("Process") );
	else
		nIndex = -1;
	tbb.iString = nIndex;
	//tbb.fsStyle |= BTNS_AUTOSIZE;
	GetToolBarCtrl().AddButtons(1, &tbb);

	// add separator
	tbb.iBitmap = I_IMAGENONE;
	tbb.idCommand = -1;
	tbb.fsStyle = TBSTYLE_SEP;
	tbb.fsState = TBSTATE_ENABLED;
	tbb.iString = -1;
	GetToolBarCtrl().AddButtons(1, &tbb);

	// add not available button
	tbb.iBitmap = LoadIconFile( IDI_ICON_NOT_AVAILABLE, NULL, IDI_ICON_NOT_AVAILABLE_D );
	tbb.idCommand = ID_REQUEST_NOTAVAILABLE;
	tbb.fsStyle = BTNS_BUTTON | TBBS_NOPREFIX;
	tbb.fsState = TBSTATE_ENABLED;
	if( bShowButtonText )
		nIndex = GetToolBarCtrl().AddStrings( _T("NA") );
	else
		nIndex = -1;
	tbb.iString = nIndex;
	//tbb.fsStyle |= BTNS_AUTOSIZE;
	GetToolBarCtrl().AddButtons(1, &tbb);

	// add send link button
	tbb.iBitmap = LoadIconFile( IDI_ICON_SEND_LINK, NULL, IDI_ICON_SEND_LINK_D );
	tbb.idCommand = ID_REQUEST_SENDLINK;
	tbb.fsStyle = BTNS_BUTTON | TBBS_NOPREFIX;
	tbb.fsState = TBSTATE_ENABLED;
	if( bShowButtonText )
		nIndex = GetToolBarCtrl().AddStrings( _T("Link") );
	else
		nIndex = -1;
	tbb.iString = nIndex;
	//tbb.fsStyle |= BTNS_AUTOSIZE;
	GetToolBarCtrl().AddButtons(1, &tbb);

	// add process button
	tbb.iBitmap = LoadIconFile( IDI_ICON_PROCESS, NULL, IDI_ICON_PROCESS_D );
	tbb.idCommand = ID_REQUEST_PROCESS;
	tbb.fsStyle = BTNS_BUTTON | TBBS_NOPREFIX;
	tbb.fsState = TBSTATE_ENABLED;
	if( bShowButtonText )
		nIndex = GetToolBarCtrl().AddStrings( _T("Send") );
	else
		nIndex = -1;
	tbb.iString = nIndex;
	//tbb.fsStyle |= BTNS_AUTOSIZE;
	GetToolBarCtrl().AddButtons(1, &tbb);

	//// add complete button
	//tbb.iBitmap = LoadIconFile( IDI_ICON_COMPLETE, NULL, IDI_ICON_COMPLETE_D );
	//tbb.idCommand = ID_RECORD_MARKASCOMPLETE;
	//tbb.fsStyle = BTNS_BUTTON | TBBS_NOPREFIX;
	//tbb.fsState = TBSTATE_ENABLED | TBSTATE_HIDDEN;
	//if( bShowButtonText )
	//	nIndex = GetToolBarCtrl().AddStrings( _T("Complete") );
	//else
	//	nIndex = -1;
	//tbb.iString = nIndex;
	////tbb.fsStyle |= BTNS_AUTOSIZE;
	//GetToolBarCtrl().AddButtons(1, &tbb);

	// attach enabled icons
	if( m_ImageIconsEnabled.GetImageCount() > 0 )
		GetToolBarCtrl().SetImageList( &m_ImageIconsEnabled );

	// attach disabled icons
	if( m_ImageIconsDisabled.GetImageCount() == m_ImageIconsEnabled.GetImageCount() )
		GetToolBarCtrl().SetDisabledImageList( &m_ImageIconsDisabled );

	// attach hot icons
	if( m_ImageIconsHot.GetImageCount() == m_ImageIconsEnabled.GetImageCount() )
		GetToolBarCtrl().SetHotImageList( &m_ImageIconsHot );

	// set up toolbar attributes
	ModifyStyle( NULL, TBSTYLE_FLAT | TBSTYLE_TRANSPARENT );
	GetToolBarCtrl().SetExtendedStyle( TBSTYLE_EX_DRAWDDARROWS );
	GetToolBarCtrl().AutoSize();
}

INT CIconToolBar::LoadIconFile(INT nID, INT nHID, INT nDID)
{	
	INT nRet = I_IMAGENONE;
	HICON hIconE = NULL;
	HICON hIconD = NULL;
	HICON hIconH = NULL;
	HBITMAP hBitmapE = NULL;
	HBITMAP hBitmapD = NULL;
	HBITMAP hBitmapH = NULL;
	INT nIconCx = 24;
	INT nIconCy = 24;

	// create the image list if needed
	if( !m_ImageIconsEnabled )
	{
		// create the image list
		if( !m_ImageIconsEnabled.Create( nIconCx, nIconCy, ILC_COLOR32 | ILC_MASK, 0, 1 ))
			return nRet;
		// set back ground color
		m_ImageIconsEnabled.SetBkColor( GetSysColor( COLOR_3DFACE ));
	}

	// create the image list if needed
	if( !m_ImageIconsDisabled )
	{
		// create the image list
		if( !m_ImageIconsDisabled.Create( nIconCx, nIconCy, ILC_COLOR32 | ILC_MASK, 0, 1 ))
			return nRet;
		// set back ground color
		m_ImageIconsDisabled.SetBkColor( GetSysColor( COLOR_3DFACE ));
	}

	// create the image list if needed
	if( !m_ImageIconsHot )
	{
		// create the image list
		if( !m_ImageIconsHot.Create( nIconCx, nIconCy, ILC_COLOR32 | ILC_MASK, 0, 1 ))
			return nRet;
		// set back ground color
		m_ImageIconsHot.SetBkColor( GetSysColor( COLOR_3DFACE ));
	}

	if( nID )
	{
		// get icon for button
		hIconE = LoadIcon( AfxGetInstanceHandle(), MAKEINTRESOURCE( nID ));
		if( nHID )
			hIconH = LoadIcon( AfxGetInstanceHandle(), MAKEINTRESOURCE( nHID ));
		if( nDID )
			hIconD = LoadIcon( AfxGetInstanceHandle(), MAKEINTRESOURCE( nDID ));

		// add the enabled icon
		nRet = m_ImageIconsEnabled.Add( hIconE );
		// if the icon is available add it
		if( hIconD )
			m_ImageIconsDisabled.Add( hIconD );
		// else add the enabled
		else
			m_ImageIconsDisabled.Add( hIconE );
		// if the icon is available add it
		if( hIconH )
			m_ImageIconsHot.Add( hIconH );
		// else add the enabled
		else	
			m_ImageIconsHot.Add( hIconE );
	}

	return nRet;
} 
